package com.kun.comic.adapter;

import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.kun.comic.model.ComicInfo;
import com.kun.comic.R;

public class ComicAdapter extends BaseAdapter {
	private List<ComicInfo> lst;
	private LayoutInflater inflater;

	public ComicAdapter(Context context, List<ComicInfo> objects) {
		inflater = LayoutInflater.from(context);
		this.lst = objects;
	}

	@Override
	public int getCount() {
		return lst.size();
	}

	@Override
	public ComicInfo getItem(int position) {
		return lst.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	private class ViewHolder {
		TextView tv;
	}

	@SuppressLint("InflateParams")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.item, null);
			holder.tv = (TextView) convertView.findViewById(R.id.tv);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.tv.setText(lst.get(position).getName());
		return convertView;
	}

}